<template>
	<view class="page">
		<view class="goods-data">
			<view class="goods-list">
				<view :class="isList?'list-view':'list-li'" v-for="(item,index) in goodsList" :key="index" v-if="goodsList.length!=0" @click="onGoodsList(item.code)">
					<view class="thumb">
						<image :src="item.cover" mode="heightFix"></image>
					</view>
					<view class="item">
						<view class="title">
							<text class="one-omit">{{item.name}}</text>
						</view>
						<view class="price flex flex-align flex-bt">
							<view class="retail-price">
								<text class="max" v-if="item.price_selling!=0">{{item.price_selling}}+</text>
								<text class="max">{{item.balance3}}积分</text>
							</view>
							<view class="btns">立即兑换</view>
						</view>
					</view>
				</view>
				<view class="empty-box"  v-if="goodsList.length==0" style="padding-top: 100rpx;">
					<image src="../../static/ic_nodata.png" mode=""></image>
					<view class="">暂无数据</view>
				</view>
			</view>
		</view>
		<tui-modal :show="modal" @cancel="hide" :custom="true" padding="40rpx 30rpx">
			<view class="tui-modal-custom">
				<view class="tui-modal-custom-text" style="margin-bottom: 30rpx;" >
					<view style="font-weight: bold;margin-bottom: 30rpx;font-size: 30rpx;">请选择需要兑换的福利</view>
					<view class="radio flex flex-align" style="margin-bottom: 20rpx;" v-for="(item,index) in fenleiList" :key="index" @click="selcekC(item.id)">
						<radio :checked="isCheck==item.id" value="" color="#f20" style="transform: scale(.7);margin-right: 10rpx;" /><text>{{item.name}}</text>
					</view>
				</view>
				<view class="flex flex-align">
					<tui-button height="72rpx" :size="28" type="white"  @click="hide">取消</tui-button>
					<view class="" style="width: 20rpx;"></view>
					<tui-button height="72rpx" :size="28" type="danger"  @click="handleClick">确定</tui-button>
				</view>
			</view>
		</tui-modal>
		<!-- <DialogBox ref="DialogBox"></DialogBox> -->
		<view class="" style="height: 150rpx;"></view>
		<TabBar :tabBarShow="2"></TabBar>
		<tui-img :show="zhiboShow" @finish='endjie'></tui-img>
	</view>
</template>

<script>
	// 引入mescroll-mixins.js
	export default {
		data() {
			return {
				type:0,
				mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
				// 下拉刷新的配置(可选, 绝大部分情况无需配置)
				downOption: {},
				// 上拉加载的配置(可选, 绝大部分情况无需配置)
				upOption: {
				},
				// 列表视图切换
				isList: true,
				// 筛选弹窗
				isScreen: false,
				// 筛选切换
				screenShow: 0,
				// 抽屉
				isDrawer: false,
				keyword: '',
				goodsList:[
				 
				],
				page:1,
				order:'sort',
				sort:'asc',
				entrance_id:'',
				dataInfo:'',
				modal:false,
				isCheck:0,
				fenleiList:[],
				zhiboShow:false
			}
		},
		onLoad(params) {
			this.getFenlei()
		},
		onReady() {
			uni.hideTabBar()
		},
		onShow() {
			let that = this
			that.getData()
			that.page=1
			that.goodsList = []
			that.getList()
			uni.$off('fcNotic');
			uni.$on('fcNotic', function(data) {
				that.zhiboShow = data
			});
			that.tui.zhiboList(1)
		},
		onReachBottom() {
			let that = this
			that.page++
			that.getList()
		},
		// #ifdef MP
		onShareAppMessage() {
			return {
				title:'分享海报',
				path:'/pages/home/home?inviter_code='+uni.getStorageSync('inviter_code'),
			};
		},
		// #endif
		onUnload() {
			uni.$off('fcNotic');
		},
		methods: {
			hide(){
				this.modal = false
			},
			selcekC(e){
				this.isCheck = e
			},
			endjie(e){
				this.zhiboShow = e
			},
			getFenlei(){
				let that = this
				that.tui.request("api.auth.live/exchangeInfo", "POST", {}, false, false, true).then((res) => {
					if (res.code == 1) {
						that.isCheck =res.data.list[0].id
						that.fenleiList = res.data.list
					}
				}).catch((res) => {})
			},
			duihuan(){
				let that = this
				that.modal = true
				return
				that.$refs['DialogBox'].confirm({
					title: '提示',
					content: '是否要兑换红包福利?',
					DialogType: 'inquiry',
					animation: 0
				}).then(() => {
					that.tui.request("api.auth.live/exchange", "POST", {exchange_red_type:that.isCheck}, false, false, true).then((res) => {
						that.tui.toast(res.info)
						if (res.code == 1) {
							that.page=1
							that.goodsList = []
							that.getList()
							that.getData()
						}
					}).catch((res) => {})
				})
				
			},
			handleClick(){
				let that = this
				that.modal = false
				that.tui.request("api.auth.live/exchange", "POST", {exchange_red_type:that.isCheck}, false, false, true).then((res) => {
					that.tui.toast(res.info)
					if (res.code == 1) {
						if(that.isCheck==2){
							setTimeout(function(){
								that.tui.href('/pages/MyCoupon/MyCoupon')
							},1000)
						}else{
							that.page=1
							that.goodsList = []
							that.getList()
							that.getData()
						}
					}
				}).catch((res) => {})
			},
			goUrl(e){
				this.tui.href(e)
			},
			getData(){
				let that = this
				that.tui.request("api.auth.center/get", "POST", {}, false, false, true).then((res) => {
					if (res.code == 1) {
						that.dataInfo = res.data
					}
				}).catch((res) => {})
			},
			getList(){
				let that = this
				that.tui.request("api.data/goodsRed", "POST", {page:that.page}, false, false, true).then((res) => {
					if (res.code == 1) {
						that.goodsList = that.goodsList.concat(res.data.list)
					}
				}).catch((res) => {})
			},
			/**
			 * 返回点击
			 */
			onBack(){
				uni.navigateBack();
			},
			
			/**
			 * 商品列表点击
			 */
			onGoodsList(e){
				uni.navigateTo({
					url: '/pages/GoodsDetails/GoodsDetails?id='+e,
					animationType: 'zoom-fade-out',
					animationDuration: 200
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	// @import  'SearchGoodsList.scss';
	page{padding-top: 20rpx;}
	/* 商品列表 */
	.goods-data {
		width: 100%;
		margin-top: 0rpx;
		/* #ifdef APP-PLUS */
		margin-top: 270rpx;
		/* #endif */
		/* #ifdef MP */
		margin-top: calc(20rpx + var(--status-bar-height));
		/* #endif */
		.goods-list {
			padding: 0 25rpx ;
			border-radius: 20rpx;
			overflow: hidden;
			.list-view {
				float: left;
				width: 49%;padding-bottom: 30rpx;
				background-color: #ffffff;
				border-radius: 20rpx;
				margin-right: 2%;
				margin-bottom: 20rpx;
				overflow: hidden;
				.thumb {
					width: 100%;
					//height: 300rpx;
					overflow: hidden;text-align: center;
					image {
	                    height: 350rpx;
					}
				}
				.item {
					width: 100%;
					.title {
						padding:10rpx 20rpx;
						text {
							width: 100%;
							color: #212121;
							font-size: 26rpx;
						}
					}
					.price {
						padding: 0 20rpx;
						.retail-price {
							height: 40rpx;
							
							.max {
								font-size: 28rpx;
								color: $base;
								font-weight: bold;
							}
						}
						.btns{background: $base;color: #fff;padding: 4rpx 10rpx;border-radius: 10rpx;font-size: 24rpx;}
						.vip-price {
							display: flex;
							align-items: flex-end;
							width: 100%;
							height: 40rpx;text-decoration: line-through;
							.min {
								display: inline-block;
								font-size: 24rpx;
								color: #212121;
							}
							.max {
								font-size: 24rpx;
								color: #212121;
							}
						}
					}
				}
			}
			.list-view:nth-child(2n) {
				margin-right: 0;
			}
			// 列表
			.list-li {
				display: flex;
				align-items: center;
				width: 100%;
				height: 300rpx;
				background-color: #ffffff;
				.thumb {
					display: flex;
					align-items: center;
					justify-content: center;
					width: 30%;
					height: 100%;
					image {
						width: 200rpx;
						height: 200rpx;
						border-radius: 10rpx;
					}
				}
				.item {
					display: flex;
					flex-direction: column;
					justify-content: center;
					width: 70%;
					height: 100%;
					border-bottom: 2rpx solid #f6f6f6;
					.title {
						padding: 20rpx;
						text {
							width: 100%;
							color: #212121;
							font-size: 26rpx;
						}
						
					}
					.price {
						padding: 0 20rpx;
						.retail-price {
							display: flex;
							align-items: flex-end;
							width: 100%;
							height: 40rpx;
							.min {
								display: inline-block;
								font-size: 24rpx;
								color: $base;
								font-weight: bold;
								transform: scale(0.7);
							}
							.max {
								font-size: 28rpx;
								color: $base;
								font-weight: bold;
							}
							.tag {
								position: relative;
								background-color: $base;
								border-radius: 4rpx;
								margin-left: 10rpx;
								text {
									display: inline-block;
									color: #ffffff;
									font-size: 24rpx;
									transform: scale(0.7);
								}
							}
							.tag:before {
								position: absolute;
								left: -6rpx;
								top: 0;
								content: '';
								width: 0;
								height: 0;
								border-top: 0rpx solid transparent;
								border-right: 10rpx solid $base;
								border-bottom: 6rpx solid transparent;
							}
						}
						.vip-price {
							display: flex;
							align-items: flex-end;
							width: 100%;
							height: 40rpx;
							.min {
								display: inline-block;
								font-size: 24rpx;
								color: #212121;
							}
							.max {
								font-size: 24rpx;
								color: #212121;
							}
						}
					}
				}
			}
		}
	}
	.basis-lg {
		padding-top: 0;
		border-radius: 20rpx 0 0 20rpx;
		flex-basis: 80% !important;
		.serve {
			/* #ifdef APP-PLUS */
			padding-top: 50rpx;
			/* #endif */
			/* #ifdef MP */
			padding-top: 140rpx;
			/* #endif */
			padding-left: 20rpx;
			padding-right: 20rpx;
			background-color: #ffffff;
			.title {
				display: flex;
				align-items: center;
				width: 100%;
				height: 80rpx;
				text {
					color: #212121;
					font-size: 28rpx;
				}
			}
			.serve-list {
				display: flex;
				flex-wrap: wrap;
				padding: 20rpx 0;
				.list {
					display: flex;
					align-items: center;
					justify-content: center;
					width: 30%;
					height: 60rpx;
					border-radius: 60rpx;
					margin-right: 4%;
					background-color: #f6f6f6;
					text {
						color: #555555;
						font-size: 24rpx;
					}
				}
				.list:nth-child(3n) {
					margin-right: 0;
				}
				.action {
					background-color: $rgba-03;
					border: 2rpx solid $base;
					text {
						color: $base;
					}
				}
			}
		}
		.price-screen {
			padding: 0 4%;
			background-color: #ffffff;
			margin-top: 20rpx;
			.title {
				display: flex;
				align-items: center;
				width: 100%;
				height: 80rpx;
				text {
					color: #212121;
					font-size: 28rpx;
				}
			}
			.price-section {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 100%;
				height: 80rpx;
				input {
					width: 180rpx;
					height: 50rpx;
					border-radius: 50rpx;
					font-size: 24rpx;
					color: #555555;
					background-color: #f6f6f6;
				}
				text {
					display: flex;
					width: 60rpx;
					height: 2rpx;
					background-color: #f6f6f6;
					margin: 0 20rpx;
				}
			}
		}
		.operation-btn {
			position: absolute;
			left: 0;
			bottom: 0;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 4%;
			width: 100%;
			height: 100rpx;
			background-color: #ffffff;
			.btn {
				display: flex;
				justify-content: center;
				align-items: center;
				width: 46%;
				height: 70rpx;
				background-color: #ffffff;
				border: 2rpx solid #f6f6f6;
				border-radius: 70rpx;
				// margin-left: 5%;
				text {
					color: #212121;
					font-size: 26rpx;
				}
			}
			.action {
				background-color: $base;
				text {
					color: #ffffff;
				}
			}
		}
	}
	
	.duihuanHeader{background:url('../../static/lipinBj.jpg') no-repeat;padding: 120rpx 0;text-align: center;background-size: 100% 100%;
		.wenzi{color: #fff;font-size: 32rpx;}
		.flex{width: 250rpx;margin: 20rpx auto;font-weight: bold;align-items: center;color: #fff;
			.prcie{font-size:56rpx;margin-top: -10rpx;margin-right: 10rpx;}
			
		}
	}
	.record-list{
		width: 100%;
		background-color: #FFFFFF;
		.list{
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 4%;
			height: 140rpx;
			border-bottom: 2rpx solid #f6f6f6;
			.title-date{
				width: 70%;
				height: 100%;
				.title{
					display: flex;
					align-items: center;
					width: 100%;
					height: 60rpx;
					text{
						font-size: 28rpx;
						font-weight: bold;
						color: #222222;
					}
				}
				.date{
					display: flex;
					align-items: center;
					width: 100%;
					height: 60rpx;
					text{
						font-size: 24rpx;
						color: #959595;
					}
				}
			}
			.integral{
				text-align: right;
				view{
					font-size: 28rpx;
					font-weight: bold;
					color: $base;
				}
			}
		}
	}
</style>
